import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { ExecuteButton } from '../Common/options'

export const LabGas = async ({ url, OptionsEvent, Permission, actionRef }) => {
    let data = {
        type: '环境监测',
        pageSize: 10,
        params: { pageIndex: 1, orderField: 'CreateTime@desc' },
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'equipmentNumber',
                title: '设备编号',
                valueType: 'input',
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'equipmentName',
                title: '设备名称',
                valueType: 'input',
                width: 400,
            },
            commonTableList.updateTime,
            {
                dataIndex: 'sensorNumber',
                title: '传感器编号',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'gasType',
                title: '气体类型',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'realTimeConcentration',
                title: '实时浓度',
                hideInSearch: true,
                valueType: 'input',
                width: 150,
                render: (_, { gasType, realTimeConcentration }) => {
                    return (
                        <div>
                            {realTimeConcentration}
                            {(() => {
                                switch (gasType) {
                                    case '温度':
                                        return ' ℃'
                                    case '湿度':
                                        return ' %'
                                    default:
                                        return ' PPM'
                                }
                            })()}
                        </div>
                    )
                },
            },
            {
                dataIndex: 'state',
                title: '状态',
                valueType: 'select',
                valueEnum: {
                    正常: '正常',
                    故障: '故障',
                    一级报警: '一级报警',
                },
                width: 150,
            },
            {
                dataIndex: 'needHandle',
                title: '是否需要处置',
                valueType: 'select',
                valueEnum: {
                    0: '不需要',
                    1: '需要',
                },
                width: 150,
            },
            commonTableList.StartTime,
            commonTableList.EndTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { organizationUuid, uuid } = record
                    return [
                        <ExecuteButton
                            actionRef={actionRef}
                            key="one"
                            title="推送气体数据"
                            url="posLabGasPushMessage"
                            path={[organizationUuid, uuid]}
                            tips="有毒气体数据推送成功!"
                        />,
                    ]
                },
            },
        ],
    }
    return data
}
